
<!-- 
# Web Socket Server
# Brandon Joffe
# 2016
#
# Copyright 2016, Brandon Joffe, All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. -->

<!-- Copyright © 2014-2016 Almsaeed Studio. All rights reserved. -->

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Home Surveillance | Dashboard</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="static/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="static/dist/css/skins/_all-skins.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="static/plugins/iCheck/flat/blue.css">
  <!-- Morris chart -->
  <link rel="stylesheet" href="static/plugins/morris/morris.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="static/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
  <!-- Date Picker -->
  <link rel="stylesheet" href="static/plugins/datepicker/datepicker3.css">

  <link rel="stylesheet" href="static/plugins/ionslider/ion.rangeSlider.css">
  <!-- ion slider Nice -->
  <link rel="stylesheet" href="static/plugins/ionslider/ion.rangeSlider.skinNice.css">
  <!-- bootstrap slider -->
  <link rel="stylesheet" href="static/plugins/bootstrap-slider/slider.css">


  <link href="static/css/main.css" rel="stylesheet">

  
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-collapse  sidebar-mini"> <!-- sidebar-collapse -->
<div class="wrapper">

  <header class="main-header">
    <!-- Logo -->
    <a href="index2.html" class="logo">
      <!-- mini logo for sidebar mini 50x50 pixels -->
      
      <!-- logo for regular state and mobile devices -->
      <span class="logo logo-lg"><b>Home</b>Surveillance</span>
    </a>
    <!-- Header Navbar: style can be found in header.less -->
    <nav class="navbar navbar-static-top">
      <!-- Sidebar toggle button-->
     <!--   <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
        <span class="sr-only">Toggle navigation</span>
      </a> -->
      <div class="navbar-custom-menu">

        <ul class="nav navbar-nav">
          <!-- Messages: style can be found in dropdown.less-->
          <!-- User Account: style can be found in dropdown.less -->
          <li class="dropdown user user-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <img src="static/dist/img/brandonjoffe.png" class="user-image" alt="User Image">
              <span class="hidden-xs">Brandon Joffe</span>
            </a>
            <ul class="dropdown-menu">
              <!-- User image -->
              <li class="user-header">
                <img src="static/dist/img/brandonjoffe.png" class="img-circle" alt="User Image">

                <p>
                  Brandon Joffe  <small>Home Surveillance With Facial Recognition</small>
                  <small>2016</small>
                </p>
              </li>
            
              <li class="user-footer">
               <!--  <div class="pull-left">
                  <a href="#" class="btn btn-default btn-flat">Profile</a>
                </div> -->
                <div class="pull-right">
                  <a href="{{ url_for('login') }}" class="btn btn-default btn-flat">Log out</a>
                </div>
              </li>
            </ul>
          </li>
          <!-- Control Sidebar Toggle Button -->
          <li>
            <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
          </li>
        </ul>
      </div>
    </nav>
  </header>
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
      <!-- Sidebar user panel -->
      <!-- search form -->
      <form action="#" method="get" class="sidebar-form">
        <div class="input-group">
          <input type="text" name="q" class="form-control" placeholder="Search...">
              <span class="input-group-btn">
                <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
                </button>
              </span>
        </div>
      </form>
      <!-- /.search form -->
      <!-- sidebar menu: : style can be found in sidebar.less -->
      <ul class="sidebar-menu">
        <li class="header">MAIN NAVIGATION</li>
        <li class="active treeview">
          <a href="#">
            <i class="fa fa-dashboard"></i> <span>Dashboard</span>
            <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
          </a>
          <ul class="treeview-menu">
            <li class="active"><a href="index.html"><i class="fa fa-circle-o"></i>Database</a></li>
            <li><a href="index2.html"><i class="fa fa-circle-o"></i>Setup Guide</a></li>
          </ul>
        </li>
         <li class="treeview">
          <a href="#">
            <i class="fa fa-laptop"></i>
            <span>Configuration</span>
            <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
          </a>
          <ul class="treeview-menu">
            <li><a href=""><i class="fa fa-circle-o"></i> Users</a></li>
            <li><a href=""><i class="fa fa-circle-o"></i> Server</a></li>
            <li><a href=""><i class="fa fa-circle-o"></i> Recognition Accuracy</a></li>
            <li><a href=""><i class="fa fa-circle-o"></i> Client Settings</a></li>
            <li><a href=""><i class="fa fa-circle-o"></i> Recording</a></li>
            <li><a href=""><i class="fa fa-circle-o"></i> Camera Settings</a></li>
          </ul>
        </li>
      </ul>
    </section>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <span class="logo-lg"><b>Home</b>Dashboard</span> 
        
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <!-- Small boxes (Stat box) -->
        <div class="row" id = "surveillance_panel">

          <!--   <div class="col-md-4 col-sm-6 col-xs-12">
                  <img class="img-thumbnail panel panel-default" id="0" src="{{ url_for('video_streamer', camNum = 0) }}"  width="540" height="320">
            </div>
            <div class="col-md-4 col-sm-6 col-xs-12">
                  <img class="img-thumbnail panel panel-default" id="1" src="{{ url_for('video_streamer', camNum = 1) }}"  width="540" height="320">
            </div>
            <div class="col-md-4 col-sm-6 col-xs-12">
                  <img class="img-thumbnail panel panel-default" id="1" src="{{ url_for('video_streamer', camNum = 1) }}"  width="540" height="320">
            </div>              
            <div class="col-md-4 col-sm-6 col-xs-12">
                  <img class="img-thumbnail panel panel-default" id="0" src="{{ url_for('video_streamer', camNum = 1) }}"  width="540" height="320">
            </div>
            <div class="col-md-4 col-sm-6 col-xs-12">
                  <img class="img-thumbnail panel panel-default" id="1" src="{{ url_for('video_streamer', camNum = 0) }}"  width="540" height="320">
            </div> -->
          
        </div> 
      <div class="row">
  
          <section class="col-lg-6 connectedSortable">
        <!-- ================================================================================================================================== -->
                
                  <div class="box box-solid bg-light-blue-gradient">
                      <div class="box-header with-border">
                        <h3 class="box-title">Faces Detected</h3>
                          <div class="btn-group pull-right">
                           <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                          </button>
                          </div>
                     </div>
                      <!-- /.box-header -->
                      <div class="box-body">
                            <div id="detected-faces">
                      <!-- /.info-box-content --> 
                           </div>                 <!-- /.users-list -->
                      </div>
                        <!-- /.box-body -->
                      <div class="box-footer text-center">
                       <div class="btn-group pull-right" id = "facedetectbtn">
                                <button type="button" id="retrain" onclick="retrainClassifier()" class="btn btn-primary btn-xs" >
                                    <i class="fa fa-refresh fa-fw"></i> Retrain Database
                                </button>
                        </div>
                      </div>
                <!-- /.box-footer -->
                  </div>
              <!--/.box -->
            <!-- ================================================================================================================================== -->

              <div class="box box-solid bg-green-gradient">
                      <div class="box-header with-border">
                        <h3 class="box-title">Camera Control Panel</h3>
                          <div class="btn-group pull-right">
                           <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                          </button>
                          </div>
                     </div>
                      <!-- /.box-header -->
                      <div class="box-body">
                      <div class="col-md-8">
                            <div class="box">
                              <div class="box-header with-border">
                               Cameras
                              </div>
                              <!-- /.box-header -->
                              <div class="box-body">
                                <div class="row">
                                  <div class="col-md-12">
                                      <div class="panel-body" id="system-cameras" >

                                      </div>     
                                  </div>
                                  <!-- /.col -->
                                </div>
                                <!-- /.row -->
                              </div>
                              <!-- ./box-body -->
                                <!-- /.row -->
                              </div>
                              <!-- /.box-footer -->
                            </div>
                            <div class="col-md-4">

                            <div class="form-group">
                                 <label>IP Camera URL</label>
                                 <input class="form-control" id="camURL" value="" placeholder="Enter stream URL">
                            </div>
                             <div class="form-group">

                               
                                <label>Video Processing Application</label>
                                    <select id="application" class="form-control">
                                        <option value="detect_motion">Motion Detection</option>
                                        <option value="detect_recognise">Face Recognition</option>
                                        <option value="motion_detect_recognise">Motion Detection & Face Recognition</option>
                                        <option value="segment_detect_recognise">Motion Object Segmentation & Face Recognition</option>
                                        <option value="detect_recognise_track">Face Recognition & Tracking</option>
                                    </select>
                               </div>

                                <div class="form-group">
                                <label>Face Detection Method</label>
                                    <select id="detectionMethod" class="form-control">
                                        <option value="opencv">Opencv Haar Cascade</option>
                                        <option value="dlib">Dlib HOG Face Detector</option>
                                    </select>
                               </div>
                            </div>
                         
                      </div>
                        <!-- /.box-body -->
                      <div class="box-footer text-center">
                       <div class="btn-group pull-right" id = "createcamerabutton">
                                <button type="button" id="addcam" onclick="addCamera()" class="btn btn-success btn-xs" >
                                    <i class="fa"></i> Add Camera
                                </button>
                        </div>
                      </div>
                <!-- /.box-footer -->
                  </div>
              <!--/.box -->
               <!-- ================================================================================================================================== -->
        </section>

      <section class="col-lg-3 connectedSortable">
  <!-- ============================================================================================================================== -->
          <div class="box box-solid bg-yellow-gradient">
              <div class="box-header with-border">
                <h3 class="box-title">Create New Alert</h3>

                <div class="box-tools pull-right">
                  <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <div class="btn-group">
                    <!-- <button type="button" class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-wrench"></i></button>
                    <ul class="dropdown-menu" role="menu">
                      <li><a href="#">Action</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li class="divider"></li>
                      <li><a href="#">Separated link</a></li>
                    </ul> -->
                  </div>
                </div>
              </div>
              <!-- /.box-header -->
              <div class="box-body">
                <div class="row">
                  <div class="col-md-12">
                          <div class="col-md-12">
                            <div class="box box-solid bg-yellow-gradient">
                              <div class="box-header with-border">
                               Alerts
                              </div>
                              <!-- /.box-header -->
                              <div class="box-body">
                                <div class="row">
                                  <div class="col-md-12">
                                      <div class="panel-body" id="alert-list" >
                              <!-- /.list-group -->
                              <!-- <a href="#" class="btn btn-default btn-block">Add Alerts Alerts</a> -->
                                      </div>     
                                  </div>
                                  <!-- /.col -->
                                </div>
                                <!-- /.row -->
                              </div>
                              <!-- ./box-body -->
                                <!-- /.row -->
                              </div>
                              <!-- /.box-footer -->
                            </div>
                            <div class="panel-body form">
                              <div class="row ">
                                    <div class="col-md-6 ">
                                        <div class="form-group">
                                            <label>Cameras</label>
                                            <select id="cameras" class="form-control">
                                                <option value="0">Camera 0</option>
                                                <option value="1">Camera 1</option>
                                                <option value="2">Camera 2</option>
                                                <option value="3">Camera 3</option>
                                                <option value="All">All</option>
                                            </select>
                                        </div>
                                         <div class="form-group">
                                            <label>Alarm State</label>
                                            <select id="alarmstate" class="form-control">
                                                <option>Armed</option>
                                                <option>Disarmed</option>
                                                <option>All</option>
                                            </select>
                                        </div>
                                           <div class="form-group">
                                             <strong>Actions</strong>
                                             <div class="checkbox ">
                                               <label>
                                                    <input id="email" type="checkbox" value="">Email Alert
                                                </label>
                                            </div>
                                            <div class="checkbox">
                                                <label>
                                                    <input id="trigger" type="checkbox" value="">Trigger Alarm
                                                </label>
                                            </div>
                                          </div>
                                    </div>
                                    <div class="col-md-6 ">
                                        
                                         <div class="form-group">
                                                <label>Event</label>
                                                <select id="event" class="form-control">
                                                    <option>Motion</option>
                                                    <option>Recognition</option>
                                                </select>
                                        </div>      
                                        <div class="form-group">
                                                <label>Select Person</label>
                                                <select id="people"  id="disabledSelect" class="form-control">
                                                    <option>Intruder</option>
                                                    <option>brandon-joffe</option>
                                                    <option>Benji Lewis</option>
                                                    <option>robby-katz</option>
                                                </select>
                                        </div>  
                                        <div class="form-group">
                                            <label>Confidence</label>
                                            <label>0-100%</label>
                                            <input type="range" name="slider3" id="slider" min="0" max="100" value="50" data-show-value="true" data-popup-enabled="true">          
                                        </div>  

                                    </div>
                                      <div class="col-lg-12">
                                          <div class="form-group">
                                               <label>Email Address</label>
                                               <input class="form-control" id="emailAddress" value="" placeholder="Enter your email address">
                                          </div>
                                    </div>
                                    
                              </div> 
                           
                            </div>
                                  
                        </div>
                      </div>
                        
                  </div>
                  <!-- /.col -->
                  <div class="box-footer text-center">
                            <div class="btn-group pull-right" id = "facedetectbtn">
                               <button type="button pull-right" onclick="createAlert()" class="btn btn-warning btn-xs">Create</button> 
                           </div>      
                </div>
            </div>
                <!-- ============================================================================================================================== -->

        </section>

         <section class="col-lg-3 connectedSortable">

             <div class="box box-solid bg-red-gradient">
                <div class="box-header">
                  <i class="fa "></i>

                  <h3 class="box-title">Control Panel</h3>
                  <!-- tools box -->
                  <div class="pull-right box-tools">
                    <!-- button with a dropdown -->
                      <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                      </button>
                  </div>
                  <!-- /. tools -->
                </div>
                <!-- /.box-header -->
                <div class="box-body ">
                            <div class="row">
                                <!-- <div class="col-md-1 col-sm-1 col-xs-1">
                                  
                                </div>  -->
                                <div class="col-md-3 col-sm-6 col-xs-6">

                                    <div><i class="fa  fa-lock fa-5x"></i></div>
                                    
                                </div>  
                                 <div class="col-md-8 col-sm-6 col-xs-6">    
                                <div>
                                        <span > 
                                        <span class="info-box-text"> Alarm Status:  <strong id="alarmStatus"></strong></span>
                                        <button type="button " id="changestate" onclick = "changeAlarmState()" class="btn btn-warning ">Arm/Disarm</button> 
                                        <button type="button " id="panic" onclick = "panic()"  class="btn btn-danger ">Panic</button>
                                       </span >

                                   </div>   
                               </div>   
                        </div>
                        <!-- /.info-box-content -->
                      <!-- </div> -->
                      <!-- /.info-box -->
                    <!-- </div> -->
                </div>
                  <!-- /.row -->
            
              </div>
            

             <div class="box box-solid bg-light-blue-gradient">
                  <div class="box-header with-border">
                    <h3 class="box-title">Add New Face</h3>
                      <div class="btn-group pull-right">
                       <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                      </button>
                      </div>
                 </div>
                  <!-- /.box-header -->
                  <div class="box-body">               
                      <form method=POST enctype=multipart/form-data action="{{ url_for('upload') }}">
                         <div class=row>
                              <div class="col-md-12 col-sm-10 col-xs-10" >
                                <input class="form-control" id="personName" name = "name" value="" placeholder="Enter new person's name" style="padding: 10px; margin-bottom: 10px; ">
                              </div> 
                              <div class="col-md-12 col-sm-10 col-xs-10">
                               <input type=file name=photo class="btn btn-xs pull-left" style="padding: 0">        
                               <input type="submit" class="btn btn-primary btn-xs pull-right">
                              </div>
                         </div>  
                       </form>                      
                      <div class="col-md-9 col-sm-8 col-xs-8">
                         <div id="face-Images">
                  <!-- /.info-box-content --> 
                       
                         </div> 
                       
                    </div>     <!-- /.users-list -->
                  </div>
                    <!-- /.box-body -->
                  <div class="box-footer text-center">
                  
                            <div class="pull-left">
                              <p class="text-black">{{message}}</p>
                            </div>
                            <div class="btn-group pull-right">
                               <button type="button" id="retrain" onclick="retrainClassifier()" class="btn btn-primary btn-xs" >
                                        <i class="fa fa-refresh fa-fw"></i> Retrain Database
                                </button>
                           
                          </div>
                  </div>
            <!-- /.box-footer -->
              </div>
          <!--/.box -->

                            <!-- =============================================================================================================================== -->

            <div class="box box-solid bg-teal-gradient">
            <div class="box-header">
              <i class="fa"></i>

              <h3 class="box-title">System Monitoring</h3>

              <div class="box-tools pull-right">
                <button type="button" class="btn bg-teal btn-sm" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
              </div>
            </div>
            <div class="box-body border-radius-none">
                
              
            </div>
            <!-- /.box-body -->
            <div class="box-footer no-border">
               <div class="row">
                <div class="col-xs-6 text-center" style="border-right: 1px solid #f4f4f4">
                  <input type="text" class="knob" id="cpu_usage" data-readonly="false" value="..." data-width="80" data-height="80" data-fgColor="#39CCCC">
                   <div class="knob-label">CPU Load %</div>
                </div>
                <!-- ./col -->
                <div class="col-xs-6 text-center" style="border-right: 1px solid #f4f4f4">
                  <input type="text" class="knob" id="memory_usage" data-readonly="false" value="..." data-width="80" data-height="80" data-fgColor="#39CCCC">
                  <div class="knob-label">Memory Usage %</div>
                </div>
                <!-- ./col -->
                <!-- ./col -->
              </div>
              <!-- /.row -->
              
            </div>
            <!-- /.box-footer -->
          </div>
          <!-- /.box -->


              <!-- =============================================================================================================================== -->
     



        </section>
              
        <!-- ./col -->
      </div>
      <!-- /.row -->
      <!-- Main row -->
      <div class="row">
        <!-- Left col -->
      
        <!-- /.Left col -->
        <!-- right col (We are only adding the ID to make the widgets sortable)-->
   
        

    </div>
  <!-- /.content-wrapper -->
  <footer class="main-footer">
    <strong>Copyright &copy; 2016 <a href="">Brandon Joffe</a>.</strong> All rights
    reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Create the tabs -->
    <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
      <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
      <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
      <!-- Home tab content -->
      <div class="tab-pane" id="control-sidebar-home-tab">
        <h3 class="control-sidebar-heading">Recent Activity</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript:void(0)">
              <i class="menu-icon fa fa-birthday-cake bg-red"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                <p>Will be 23 on April 24th</p>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <i class="menu-icon fa fa-user bg-yellow"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Frodo Updated His Profile</h4>

                <p>New phone +1(800)555-1234</p>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <i class="menu-icon fa fa-envelope-o bg-light-blue"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Nora Joined Mailing List</h4>

                <p>nora@example.com</p>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <i class="menu-icon fa fa-file-code-o bg-green"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Cron Job 254 Executed</h4>

                <p>Execution time 5 seconds</p>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

        <h3 class="control-sidebar-heading">Tasks Progress</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript:void(0)">
              <h4 class="control-sidebar-subheading">
                Custom Template Design
                <span class="label label-danger pull-right">70%</span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <h4 class="control-sidebar-subheading">
                Update Resume
                <span class="label label-success pull-right">95%</span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-success" style="width: 95%"></div>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <h4 class="control-sidebar-subheading">
                Laravel Integration
                <span class="label label-warning pull-right">50%</span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-warning" style="width: 50%"></div>
              </div>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)">
              <h4 class="control-sidebar-subheading">
                Back End Framework
                <span class="label label-primary pull-right">68%</span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-primary" style="width: 68%"></div>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

      </div>
      <!-- /.tab-pane -->
      <!-- Stats tab content -->
      <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
      <!-- /.tab-pane -->
      <!-- Settings tab content -->
      <div class="tab-pane" id="control-sidebar-settings-tab">
        <form method="post">
          <h3 class="control-sidebar-heading">General Settings</h3>

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Report panel usage
              <input type="checkbox" class="pull-right" checked>
            </label>

            <p>
              Some information about this general settings option
            </p>
          </div>
          <!-- /.form-group -->

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Allow mail redirect
              <input type="checkbox" class="pull-right" checked>
            </label>

            <p>
              Other sets of options are available
            </p>
          </div>
          <!-- /.form-group -->

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Expose author name in posts
              <input type="checkbox" class="pull-right" checked>
            </label>

            <p>
              Allow the user to show his name in blog posts
            </p>
          </div>
          <!-- /.form-group -->

          <h3 class="control-sidebar-heading">Chat Settings</h3>

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Show me as online
              <input type="checkbox" class="pull-right" checked>
            </label>
          </div>
          <!-- /.form-group -->

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Turn off notifications
              <input type="checkbox" class="pull-right">
            </label>
          </div>
          <!-- /.form-group -->

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Delete chat history
              <a href="javascript:void(0)" class="text-red pull-right"><i class="fa fa-trash-o"></i></a>
            </label>
          </div>
          <!-- /.form-group -->
        </form>
      </div>
      <!-- /.tab-pane -->
    </div>
  </aside>
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 2.2.3 -->
<script type="text/javascript" src="//code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">

             function addCamera() {
                            //getting selected option from dropdowns
                            var camURL = document.getElementById("camURL").value;
                       
                            var e1 = document.getElementById("application");
                            var application = e1.options[e1.selectedIndex].value; 
                            var e2 = document.getElementById("detectionMethod");
                            var detectionMethod = e2.options[e2.selectedIndex].value;        
                           
                            alertstyle = "alert-success";


                            var icon = '<i class="fa fa-video-camera fa-3x" aria-hidden="true"></i>'
                            var icondiv = '<div class="product-info">' + icon  +'</div>'

                            if(detectionMethod == "opencv"){
                                dlibDetection = false;
                            }
                            else{
                                dlibDetection =true
                            }

                            $('#addcam').html('<i class="fa fa-spin fa-cog fa-3x fa-fw" style="font-size:12px;"></i> Adding Camera');

                            console.log(camURL + " " + application + " " + detectionMethod);
                            $.ajax({
                                  type: "POST",
                                  url: "{{ url_for('add_camera') }}",
                                  data : {'camURL': camURL, 'application': application, 'detectionMethod': dlibDetection}, 
                                  success: function(cam) {
                                    console.log(cam);

                                        var camdiv = document.createElement("div");
                                        camdiv .setAttribute("class","alert alert-dismissable " + alertstyle);   
                                        var btn = document.createElement("BUTTON");        
                                        btn.setAttribute("type","button");    
                                        btn.setAttribute("class", "close"); 
                                        btn.setAttribute("data-dismiss", "alert");  
                                        btn.setAttribute("aria-hidden","true"); 
                                        btn.setAttribute("onclick","removeCamera(this.id)"); 
                                        btn.setAttribute("id","camera_" + cam.camNum);  
                                        btn.innerHTML = "&times;";
                                        camdiv.innerHTML = '<div class="text-center"><span>' + icon + '<div><strong>Camera '+ cam.camNum + ' FPS: <strong id="camera_' + cam.camNum+ '_fps">' + "Loading... </strong></div><div>" +'<font size="0.9">' + camURL+'<font></span></div>';
                                        camdiv.appendChild(btn);
                                        document.getElementById("system-cameras").appendChild(camdiv);

                                        var viddiv = document.createElement("div");
                                        viddiv.setAttribute("class","col-md-4 col-sm-6 col-xs-12");  
                                        var vidstream = document.createElement("img");
                                        vidstream.setAttribute("class","img-thumbnail panel panel-default"); 
                                        vidstream.setAttribute("id",cam.camNum); 
                                        vidstream.setAttribute("src","/video_streamer/" + cam.camNum); 
                                        vidstream.setAttribute("width","540"); 
                                         vidstream.setAttribute("height","320");
                                        viddiv.appendChild(vidstream);
                                        document.getElementById("surveillance_panel").appendChild(viddiv);

                                        $('#addcam').html('Add Camera');

                                  },
                                  error: function(error) {
                                    console.log(error);
                                  }
                            });

                            
                }
            function retrainClassifier(){
                    
                      $('#retrain').html('<i class="fa fa-refresh fa-spin fa-3x fa-fw" style="font-size:12px;"></i> Retraining Database');

                      $.ajax({
                                  type: "POST",
                                  url: "{{ url_for('retrain_classifier') }}",
                                  data : {}, 
                                  success: function(results) {
                                    console.log(results.finished);
                                   
                                    $('#retrain').html('<i class="fa fa-refresh fa-fw"></i> Retrain Database');

                                  },
                                  error: function(error) {
                                    console.log(error);
                                  }
                           });
                }
            function removeFace(id){
                    
                      //var text=$('#' + id + '_input').html();
                      var values = id.split('_');

                      var name = values[0];
                      var camera = values[1];
                      var person =document.getElementById(name + "_" + camera); //remove person from div
                      person.parentNode.removeChild(person);

                      $.ajax({
                                  type: "POST",
                                  url: "{{ url_for('remove_face') }}",
                                  data : {'predicted_name': name, 'camera': camera}, 
                                  success: function(results) {
                                    console.log(results);
                                    var person =document.getElementById(name + "_" + camera); //sometimes faces get reloaded before before they have been deleted this ensures they are removed from the list
                                    person.parentNode.removeChild(person);
                                                                         
                                  },
                                  error: function(error) {
                                    console.log(error);
                                  }
                           });
                }

            function addFace(id){
                    
                      var values = id.split('_');

                      var name = values[0];
                      var camera = values[1];

                      if(values[2]=='trust') {
                            var trust =true
                      }
                      else{
                           
                            var trust =false
                      }
                      var newName = document.getElementById(name + "_" + camera + "_input").value;
                      
                      var person =document.getElementById(name + "_" + camera); //remove person from div
                      person.parentNode.removeChild(person);

                  
                      $.ajax({
                                  type: "POST",
                                  url: "{{ url_for('add_face') }}",
                                  data : {'person_id': name, 'new_name': newName, 'camera' : camera, 'trust':trust}, 
                                  success: function(results) {
                                    console.log(results);
                                        
                                  },
                                  error: function(error) {
                                    console.log(error);
                                  }
                           });

                }

                function createAlert() {
                            //getting selected option from dropdowns
                            emailAddress = document.getElementById("emailAddress").value;

                            var confidence = document.getElementById("slider").value;
                           

                            var e = document.getElementById("cameras");
                            var cam = e.options[e.selectedIndex].value; 
                            var e1 = document.getElementById("event");
                            var eventd = e1.options[e1.selectedIndex].text; 
                            var e2 = document.getElementById("alarmstate");
                            var alarm = e2.options[e2.selectedIndex].text; 
                            var e3 = document.getElementById("people");
                            var pers = e3.options[e3.selectedIndex].text;  

                            var email = false;
                            var push = false;
                            var triggerA = false;
                            var notifyP = false;

                       
                            if(document.getElementById("email").checked==true) {
                                email = true;
                                alertstyle = "alert-danger"
                            }
                            // if(document.getElementById("push").checked==true) {
                            //     push = true;
                            //     alertstyle = "alert-info"
                            // }
                            if(document.getElementById("trigger").checked==true) {
                                triggerA = true;
                                alertstyle = "alert-danger"
                            }
                            // if(document.getElementById("notify").checked==true) {
                            //     notifyP = true;
                            //     alertstyle = "alert-danger"
                            // }


                            //ajax post used to send alert data via json [ 'push_alert': push,'email_alert':email, 'trigger_alarm':triggerA, 'notify_police':notifyP]
                             $.ajax({
                                  type: "POST",
                                  url: "{{ url_for('create_alert') }}",
                                  data : {'camera': cam, 'eventdetail': eventd, 'alarmstate': alarm, 'person': pers, 'push_alert': push,'email_alert':email, 'trigger_alarm':triggerA,'notify_police':notifyP,'emailAddress':emailAddress,'confidence':confidence}, 
                                  success: function(results) {
                                    console.log(results);
                                   

                                        var alertdiv = document.createElement("div");
                                        alertdiv.setAttribute("class","alert alert-dismissable " + alertstyle);   
                                        var btn = document.createElement("BUTTON");        
                                        btn.setAttribute("type","button");    
                                        btn.setAttribute("class", "close"); 
                                        btn.setAttribute("data-dismiss", "alert");  
                                        btn.setAttribute("aria-hidden","true"); 
                                        btn.setAttribute("onclick","removeAlert(this.id)"); 
                                        btn.setAttribute("id",results.alert_id);  
                                        btn.innerHTML = "&times;";
                                        alertdiv.innerHTML = results.alert_message;
                                        alertdiv.appendChild(btn);
                                        document.getElementById("alert-list").appendChild(alertdiv);

                                  },
                                  error: function(error) {
                                    console.log(error);
                                  }
                            });                         
                }

                function removeAlert(id) {
                      $.ajax({
                              type: "POST",
                              url: "{{ url_for('remove_alert') }}",
                              data : {'alert_id': id}, 
                              success: function(results) {
                                console.log(results);
                          
                              },
                              error: function(error) {
                                console.log(error);
                              }
                        });
                 }

                $(document).ready(function(){

                    var socket = io.connect('http://' + document.domain + ':' + location.port + '/surveillance');

                    var numbers_received = [];
                    var people_received = [];

                     $("#changestate").click(function(){
                        socket.emit('alarm_state_change');
                        return false;
                     }); 

                    $("#panic").click(function(){
                        socket.emit('panic');
                        return false;
                     }); 

                    socket.on('my response', function(msg) {           //socket.on used to define event handeler
                        $('#log').append('<p>' + msg.data + '</p>');
                    });

                    $('form#emit').submit(function(event) {
                        
                    });

                    $('form#broadcast').submit(function(event) {
                        socket.emit('my broadcast event', {data: $('#broadcast_data').val()});
                        return false;
                    });

                    socket.on('people_detected', function(json) {   
                   
                        console.log("Received peopledata in Loop" + json);
                        var people = JSON.parse(json);
                        people_string = '';
                       
                        for (var i = 0; i < people.length; i++){

                            if(!document.getElementById(people[i].identity + "_" + people[i].camera)){
                                    var img_string = "/get_faceimg/"+ people[i].identity +"_" + people[i].camera + "#";

            /////////////////////////////////////////////////////////////////// Main divs
                                    var maindiv = document.createElement("div");
                                    maindiv.setAttribute("class", "col-md-3 ");
                                    maindiv.setAttribute("id", people[i].identity + "_"+ people[i].camera);
                                    var thumbdiv = document.createElement("div");
                                    thumbdiv.setAttribute("class", "thumbnail ");
            /////////////////////////////////////////////////////////////////// img element
                                    var imgj = document.createElement("img");
                                    imgj.setAttribute("src", img_string + new Date().getTime());
                                    imgj.setAttribute("height", "100");
                                    imgj.setAttribute("width", "100");
                                    imgj.setAttribute("id", people[i].identity + "_" + people[i].camera + "_image");
                                    imgj.setAttribute("alt", "Random Name");
                                    imgj.setAttribute("class", "person"); //img-circle 
                                    //document.getElementById("progressbar").appendChild(imgj);
                                    thumbdiv.appendChild(imgj);
            /////////////////////////////////////////////////////////////////// name element
                                    var name = document.createElement("p");
                                    name.setAttribute("class", "text-center predictedName text-black");
                                    name.setAttribute("id", people[i].identity + "_"+ people[i].camera+"_prediction");
                                    name.innerHTML = "<strong>"+people[i].prediction+"</strong>";
                                    thumbdiv.appendChild(name);
            /////////////////////////////////////////////////////////////////// button element
                                    var aligndiv = document.createElement("div");
                                    aligndiv.setAttribute("class","pull-right");   

                                    var btndiv = document.createElement("div");
                                    btndiv.setAttribute("class","btn-group");   
                                    var btn = document.createElement("BUTTON");        
                                    btn.setAttribute("type","button");    
                                    btn.setAttribute("class", "btn btn-default btn-xs dropdown-toggle");  
                                    btn.setAttribute("data-toggle","dropdown");  

                                    var spn = document.createElement("span");
                                    spn.setAttribute("class","caret");    
                                    btn.appendChild(spn);
                                   
                                    var list = document.createElement("ul");
                                    list.setAttribute("class","dropdown-menu text-centre"); 
                                    list.setAttribute("role","menu"); 
                                    list.setAttribute("id","faceActionList"); 


                                    var listitem = document.createElement("li");
                                    var inner = document.createElement("a");
                                    inner.setAttribute("id",people[i].identity + "_"+ people[i].camera+"_remove"); 
                                    inner.setAttribute("onclick","removeFace(this.id)"); 
                                    inner.innerHTML = "Remove";
                                    //addFace(id)
                                    listitem.appendChild(inner);
                                    list.appendChild(listitem);

                                    var listitem = document.createElement("li");
                                    var inner = document.createElement("a");
                                    inner.setAttribute("id",people[i].identity + "_"+ people[i].camera+"_trust"); 
                                    inner.setAttribute("onclick","addFace(this.id)"); 
                                    inner.innerHTML = "Trust";
                                    
                                    listitem.appendChild(inner);
                                    list.appendChild(listitem);

                                    var listitem = document.createElement("li");
                                    var inner = document.createElement("a");
                                    inner.setAttribute("data-toggle","modal"); 
                                    inner.setAttribute("id","addfacebtnID"); 
                                    inner.setAttribute("data-target","#"+people[i].identity + "_"+ people[i].camera+"_modal"); 
                                    inner.innerHTML = "Add New Face";
                                  
                                    listitem.appendChild(inner);
                                    list.appendChild(listitem);   

                                    btndiv.appendChild(btn);
                                    btndiv.appendChild(list);
                                    aligndiv.appendChild(btndiv);

                                    //document.getElementById("progressbar").appendChild(btndiv);   
                                    thumbdiv.appendChild(aligndiv);
             ///////////////////////////////////////////////////////////////////  progress bar element                     
                                    var d1 = document.createElement("div");
                                    d1.setAttribute("class","progress");
                                    var d2 = document.createElement("div");
                                    //var values = people[i].prediction.split('_');
                                    //var name = values[0];
                                    var conf = people[i].confidence; 
                                    console.log("New Person: " + people[i].prediction + ":"+people[i].confidence); 
                                    if(people[i].prediction != "unknown"){
                                        d2.setAttribute("class","progress-bar progress-bar-success");
                                        d2.setAttribute("role","progress-bar progress-bar-success");   
                                    }
                                    else{
                                           
                                        d2.setAttribute("class","progress-bar progress-bar-danger");
                                        d2.setAttribute("role","progress-bar progress-bar-danger");
                                        conf = people[i].confidence;
                                    }         
                                    
                                    d2.setAttribute("aria-valuenow","50");
                                    d2.setAttribute("aria-valuemin","0");
                                    d2.setAttribute("aria-valuemax","100");
                                    d2.setAttribute("style","width:" + conf +"%");
                                    d2.innerHTML = conf + "%";
                                    d1.appendChild(d2);

                                    var info = document.createElement("span");        
                                    info.setAttribute("id","detectioinfo"); 
                                    info.setAttribute("style","text-align:center; color:black; font-size:70%;");         
                                    info.innerHTML = "Camera " + people[i].camera + "  -  " + people[i].timeD;       
                                              
                           
             /////////////////////////////////////////////////////////////////////////////////////
                                 
                                    var modal = document.createElement("div");
                                    modal.setAttribute("class","modal modal-default fade col-md-3 text-center");
                                    modal.setAttribute("id",people[i].identity + "_" + people[i].camera + "_modal");
                                    modal.setAttribute("tabindex","-1");
                                    modal.setAttribute("role","dialog");
                                    modal.setAttribute("aria-labelledby","myModalLabel");
                                    modal.setAttribute("aria-hidden","true");
                                


                                    var dialog = document.createElement("div");
                                    dialog.setAttribute("class","modal-dialog");
                                    //modal.appendChild(dialog);

                                    var content = document.createElement("div");
                                    dialog.setAttribute("class","modal-content");
                                    //dialog.appendChild(content);

                                    var header = document.createElement("div");
                                    header.setAttribute("class","modal-header");
                                    //dialog.appendChild(content);

                                    var btn2 = document.createElement("BUTTON");        
                                    btn2.setAttribute("type","button");    
                                    btn2.setAttribute("class", "close");  
                                    btn2.setAttribute("data-dismiss","modal");  
                                    btn2.setAttribute("aria-hidden","true");  
                                    btn2.innerHTML = "&times;";

                                    header.appendChild(btn2);

                                    var title = document.createElement("h4");        
                                    title.setAttribute("id","myModalLabel");    
                                    title.setAttribute("class", "modal-title text-black text-center");  
                                    title.innerHTML = "Add face to Database";
                                  
                                    header.appendChild(title);                
                                    content.appendChild(header);

                                    var body = document.createElement("div");
                                    body.setAttribute("class","modal-body");

                                    var rowdiv = document.createElement("div");
                                    rowdiv.setAttribute("class","row");

                                    var imgj1 = document.createElement("img");
                                    imgj1.setAttribute("src", img_string + new Date().getTime());
                                    imgj1.setAttribute("height", "100");
                                    imgj1.setAttribute("width", "100");
                                    imgj1.setAttribute("id", people[i].identity + "_" + people[i].camera+ "_imageModal");
                                    imgj1.setAttribute("class", "person"); //img-circle 
                                    
                                    rowdiv.appendChild(imgj1);

                                    body.appendChild(rowdiv);

                                    var name = document.createElement("h4");
                                    name.setAttribute("class", "text-center text-black");
                                    name.setAttribute("id", people[i].identity + "_" + people[i].camera+ "nameID");
                                    var values = people[i].prediction.split('_');
                                    var nameprediction = values[0];
                                    name.innerHTML = "<strong>" + nameprediction + " ?</strong>";

                                    body.appendChild(name);

                                    var form = document.createElement("div");
                                    form.setAttribute("class","form-group has-primary");

                                    var input = document.createElement("input");
                                    input.setAttribute("class","form-control"); 
                                    input.setAttribute("placeholder","Enter Name"); 
                                    input.setAttribute("type","text");  
                                    input.setAttribute("id", people[i].identity + "_" + people[i].camera+ "_input");   

                                    form.appendChild(input);                
                                    body.appendChild(form);
                                 
                                    content.appendChild(body);

                                    var footer = document.createElement("div");
                                    footer.setAttribute("class","modal-footer");
                                    //dialog.appendChild(content);

                                    var btn3 = document.createElement("BUTTON");        
                                    btn3.setAttribute("type","button");    
                                    btn3.setAttribute("class", "btn btn-primary pull-right");  
                                    btn3.setAttribute("data-dismiss","modal");  
                                    btn3.setAttribute("aria-hidden","true"); 
                                    btn3.setAttribute("id",people[i].identity + "_" + people[i].camera + "_add");  
                                    btn3.setAttribute("onclick","addFace(this.id)");  
                                    btn3.innerHTML = "Add Face";

                                    footer.appendChild(btn3);

                                    content.appendChild(footer);
                                    dialog.appendChild(content);
                                    modal.appendChild(dialog);

                                    thumbdiv.appendChild(d1);
                                    thumbdiv.appendChild(info);  
                                   
                                    maindiv.appendChild(thumbdiv);
                            

                                    document.getElementById("detected-faces").appendChild(maindiv);
                                    document.getElementById("detected-faces").appendChild(modal);
                            }
                            else{

                                var x = document.getElementById(people[i].identity+ "_" + people[i].camera).getElementsByClassName("progress-bar");
                                    
                                for (var j = 0; j < x.length; j++) {
                                        console.log("Updating detected face");
                                        var values = people[i].prediction.split('_');
                                        var name = values[0];
                                        var conf = people[i].confidence; 
                                        ///////////////////////
                                        if(name != "unknown"){
                                            x[j].setAttribute("class","progress-bar progress-bar-success");
                                            x[j].setAttribute("role","progress-bar progress-bar-success");
                                            var y = document.getElementById(people[i].identity+ "_" + people[i].camera).getElementsByClassName("predictedName");
                                            y[0].innerHTML = "<strong>"+people[i].prediction+"</strong>";
                                        
                                        }
                                        else{
                                               
                                            // x[j].setAttribute("class","progress-bar progress-bar-failure");
                                            // x[j].setAttribute("role","progress-bar progress-bar-failure");
                                            conf = people[i].confidence; 
                                        }       

                                        //////////////////////                          
                                        x[j].setAttribute("style","width:" + conf +"%");
                                        x[j].innerHTML = conf +"%";
                                    }
                                console.log("Updating image: " + people[i].identity);  
                                var img_string = "/get_faceimg/"+people[i].identity +'_'+ people[i].camera+ "#";
                                $('#' + people[i].identity + "_" + people[i].camera+ '_image').attr('src',  img_string  + new Date().getTime()); //jquery used to update image
                                $('#' + people[i].identity + "_" + people[i].camera+ "_imageModal").attr('src',  img_string  + new Date().getTime()); //update modal image 
                            }

                            //console.log(people_string);
              
                        }   

                        
                    });
                     
                      socket.on('alarm_status', function(json) {   

                               console.log("Alarm Status: " + json);
                               var alarm_status = JSON.parse(json);

                               if(alarm_status.triggered == true){

                                    $("#alarmStatus").html("Alarm Triggered");
                               }
                               else{
                                    $("#alarmStatus").html(alarm_status.state);

                               }         

                        });
                     

                       socket.on('system_monitoring', function(json) {   

                               console.log("System Monitoring: " + json);
                               var systemState = JSON.parse(json);
                                var i = 0;
                               for (; i < systemState.processingFPS.length;i++) {
                                   // document.getElementById( "camera_" + i + "_fps").text = systemState.processing_fps[i];
                                    $("#camera_" + i + "_fps").html(systemState.processingFPS[i]);

                                   
                               }
                              
                               document.getElementById("cpu_usage").value = systemState.cpu;
                               document.getElementById("memory_usage").value = systemState.memory;
                               
                        });

                      socket.on('system_data', function(json) {   

                               console.log("System Data: " + json);
                               var system_data = JSON.parse(json);
                               var person;
                               var i = 0;
                               people_string = '';
                               for (; i < system_data.people.length;i++) {
                                    people_string = people_string + '<option>' + system_data.people[i]+ '</option>';
                               }
                                $('#people').html(people_string);

                               var i = 0;
                               camera_string = '';
                               for (; i < system_data.camNum;i++) {
                                    camera_string = camera_string + '<option value="' + i.toString() + '"> Camera ' + i + '</option>';
                               }
                               camera_string = camera_string + '<option value="All">All</option>';
                                $('#cameras').html(camera_string);

                                if (system_data.onConnect == true){
                                     
                                    //  var myNode = document.getElementById("foo");
                                    //  while (myNode.firstChild) {
                                    //       myNode.removeChild(myNode.firstChild);
                                    // }

                                     var icon = '<i class="fa fa-video-camera fa-3x" aria-hidden="true"></i>'
                                     var icondiv = '<div class="product-info">' + icon  +'</div>'
                                   
                                     var i = 0;
                                     for (; i < system_data.cameras.length;i++) {

                                          var elementExists = document.getElementById("camera_"+system_data.cameras[i].camNum)
                                          if (elementExists != null){
                                            break
                                          } 

                                          console.log("Cameras:" + system_data.cameras[i]);
                                          var camdiv = document.createElement("div");
                                          camdiv .setAttribute("class","alert alert-dismissable alert-success");   
                                          var btn = document.createElement("BUTTON");        
                                          btn.setAttribute("type","button");    
                                          btn.setAttribute("class", "close"); 
                                          btn.setAttribute("data-dismiss", "alert");  
                                          btn.setAttribute("aria-hidden","true"); 
                                          btn.setAttribute("onclick","removeCamera(this.id)"); 
                                          btn.setAttribute("id","camera_" + system_data.cameras[i].camNum);  
                                          btn.innerHTML = "&times;";
                                          camdiv.innerHTML = '<div class="text-center"><span>' + icon + '<div><strong>Camera '+ system_data.cameras[i].camNum + ' FPS: <strong id="camera_' + system_data.cameras[i].camNum+ '_fps">' + "Loading... </strong></div><div>" +'<font size="0.9">' + system_data.cameras[i].url +'<font>'+'</span></div>';
                                          camdiv.appendChild(btn);
                                          document.getElementById("system-cameras").appendChild(camdiv);


                                          var viddiv = document.createElement("div");
                                          viddiv.setAttribute("class","col-md-4 col-sm-6 col-xs-12");  
                                          var vidstream = document.createElement("img");
                                          vidstream.setAttribute("class","img-thumbnail panel panel-default"); 
                                          vidstream.setAttribute("id",system_data.cameras[i].camNum); 
                                          vidstream.setAttribute("src","/video_streamer/" + system_data.cameras[i].camNum); 
                                          vidstream.setAttribute("width","540"); 
                                          viddiv.appendChild(vidstream);
                                          document.getElementById("surveillance_panel").appendChild(viddiv);

                                     }
                                     console.log("Alerts:" + system_data.alerts);
                                     var i = 0;
                                     for (; i < system_data.alerts.length;i++) {

                                          var elementExists = document.getElementById(system_data.alerts[i].alert_id)
                                          if (elementExists != null){
                                            break
                                          } 


                                          var alertdiv = document.createElement("div");
                                          alertdiv.setAttribute("class","alert alert-dismissable alert-danger");   
                                          var btn = document.createElement("BUTTON");        
                                          btn.setAttribute("type","button");    
                                          btn.setAttribute("class", "close"); 
                                          btn.setAttribute("data-dismiss", "alert");  
                                          btn.setAttribute("aria-hidden","true"); 
                                          btn.setAttribute("onclick","removeAlert(this.id)"); 
                                          btn.setAttribute("id", system_data.alerts[i].alert_id);  
                                          btn.innerHTML = "&times;";
                                          alertdiv.innerHTML = system_data.alerts[i].alert_message;
                                          alertdiv.appendChild(btn);
                                          document.getElementById("alert-list").appendChild(alertdiv);

                                     }

                                }

                              
                              
                        });


                });


     </script>
 
<script src="static/plugins/ionslider/ion.rangeSlider.min.js"></script>
<!-- Bootstrap slider -->
<script src="static/plugins/bootstrap-slider/bootstrap-slider.js"></script>

<script src="static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.6 -->
<script src="static/bootstrap/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="static/plugins/morris/morris.min.js"></script>
<!-- Sparkline -->
<script src="static/plugins/sparkline/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="static/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="static/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="static/plugins/knob/jquery.knob.js"></script>
<!-- daterangepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="static/plugins/daterangepicker/daterangepicker.js"></script>
<!-- datepicker -->
<script src="static/plugins/datepicker/bootstrap-datepicker.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="static/dist/js/app.min.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="static/dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="static/dist/js/demo.js"></script>
</body>
</html>
